package com.suanfa.sort;

/**
 * Created by buguniao on 16/2/10.
 */
public class Insertion extends SuanFaTemplate{
    public static void main(String[] args){
        Insertion insertion = new Insertion();
        double[] arr = insertion.getRandomArray(64000);
        long time=insertion.run(arr);
        System.out.print("time cost : "+time);
    }
    @Override
    public long run(double[] arr) {
        long t1=System.currentTimeMillis();
        for(int i=1;i<arr.length;i++){
            for(int j=i;j>0 && less(arr[j],arr[j-1]);j--){
                exchange(arr,j,j-1);
            }
        }
        long t2 = System.currentTimeMillis();
//        System.out.println("排序后的数组："+ Arrays.toString(arr));
        return t2-t1;
    }
}
